import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[]array={1,9,2,8,3,7,4,6,5};
        //bubbleSort(array);
        selectSort(array);
        System.out.println(Arrays.toString(array));
    }

    private static void selectSort(int[] array) {
        for (int i = 0; i < array.length; i++) {
            int minIndex = i;
            for (int j = i+1; j < array.length; j++) {
                if(array[j]<array[minIndex]){
                    minIndex = j;
                }
            }
            swap(array,minIndex,i);
        }
    }

    private static void swap(int[] array, int a, int b) {
        int tmp = array[a];
        array[a] = array[b];
        array[b] = tmp;
    }

    private static void bubbleSort(int[] array) {
        int n = array.length;
        boolean flag = false;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n-1-i ; j++) {
               if(array[j]> array[j+1]){
                   flag = true;
                   int tmp = array[j];
                   array[j] = array[j+1];
                   array[j+1] = tmp;
               }
            }
            if(!flag)
                break;
        }
    }
}